package com.xianzhi.service.impl;

import com.xianzhi.bean.Ad;
import com.xianzhi.dao.AdDao;
import com.xianzhi.dto.AdDto;
import com.xianzhi.service.AdService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdServiceImpl implements AdService {
    @Autowired
    private AdDao adDao;

    @Override
    public List<AdDto> selectByPage(AdDto adDto) {
        List<AdDto> result = new ArrayList();
        Ad condition = new Ad();
        //将原对象adDto中的数据复制到目标对象condition
        BeanUtils.copyProperties(adDto,condition);
        //调用dao的方法
        List<Ad> adList = adDao.selectByPage(condition);
        for (Ad ad:adList) {
            AdDto adDtoTemp = new AdDto();
            BeanUtils.copyProperties(ad,adDtoTemp);
            result.add(adDtoTemp);
        }
        return result;
    }

    @Override
    public boolean add(AdDto adDto) {
        adDao.insert(null);
        return false;
    }
}
